<?php
$update_profile_bin = '/home/luanjunyi/yhhd/py/taras/tools/update_profile ';

error_reporting(E_ALL);
ob_implicit_flush();
ini_set('display_errors', '1');


if (isset($_GET['op']) && $_GET['op'] == 'do') {

  // update sina weibo profile
  $email = $_POST['email'];
  $nick = $_POST['nick'];
  $description = $_POST['description'];
  $photo_url = $_POST['photo_url'];
  $sina_tags = $_POST['sina_tags'];


  $sina_tags = str_replace('＃', '#', $sina_tags);
  $sina_tags = str_replace('#', ',', $sina_tags);

  $cmd = $update_profile_bin . sprintf("-e '%s' -c '%s' -d '%s' -i '%s' -t '%s'",
                                       $email, $nick, $description, $photo_url, $sina_tags);

  chdir('../tmp/');
  echo $cmd . "<br />";
  echo "<pre>";
  system($cmd . " 2>&1");
  echo "</pre>";
  echo "done!";
  return;
}

if (!isset($_GET['email'])) {
  die("email not set...");
}

include_once "../config.php";
require_once "../util.php";

connect_db();

$email = $_GET['email'];
$sql = "select passwd from sina_user where email = '$email'";
$ret = mysql_query($sql);
if (!$ret) {
  echo "$sql failed:" . mysql_error();
  return;
}
if (mysql_num_rows($ret) < 1) {
  die('no such user in DB:' . $email);
}

$passwd = mysql_fetch_assoc($ret);
$passwd = $passwd['passwd'];
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
   <script type="text/javascript" src="/lib/js/jquery.js"></script>
   <link rel="stylesheet" type="text/css" href="/lib/css/reset.css">
   <link rel="stylesheet" type="text/css" href="css/import_user.css">
   <script type="text/javascript" src="/lib/js/sprintf.js"></script>

   <title><?php echo $email ?> | 更新profile</title>
</head>

<body>
  <div id="profile-div">
  <?php echo "<b>$email | $passwd </b><hr />"; ?>
  <form id="adhoc-form" action="update_profile?op=do" method="post" target="stat-frame" class="float-form">
    <input type="hidden" name="email" value="<?php echo $email ?>" />
    <label>昵称:</label><input type="text" name="nick" />
    <label>描述:</label><textarea name="description" ></textarea>
    <label>新浪标签:</label><input type="text" name="sina_tags" />
    <label>头像地址:</label><input type="text" name="photo_url" />
    <input type="submit" value="更新profile" />
  </form>
  <iframe id="stat" width="500" height="300" name="stat-frame">
        
  </iframe>

  <div>
</body>
</html>
